package com.itcam.iostream;

import java.io.*;

/**
 * Author:Cammy.Wu
 * Date:2024-05-14
 * Description:实现Serializable接口
 */

public class SerializableStreamDemo01 {
    public static void main(String[] args) throws IOException {
        // 序列化：将内存中对象 --》文件中
        // 创建一个对象
        People cammy = new People("Cammy", 28);
        // 对象流
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("E:\\IOstream\\SerializableStreamDemo.txt")));
        // 向外写
        oos.writeObject(cammy);
        // 关闭流
        oos.close();

    }
}

class People implements Serializable {
    private static final long seriaVersinUID = 123456L;
    private String name;
    private int age;

    public People() {
    }

    public People(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "People{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}



